package com.lee.serviceagent.ocr.tesseract;

import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Size;


import static org.bytedeco.opencv.global.opencv_imgcodecs.imread;
import static org.bytedeco.opencv.global.opencv_imgproc.*;

/**
 * @author lee
 * @description class
 * @date 2025/8/19 上午10:53
 */
public class ImagePreprocessing {
    public Mat preprocessImage(String imagePath) {
        //读取图像
        Mat image = imread(imagePath);
        //转换为灰度图像
        Mat gray = new Mat();
        cvtColor(image, gray, COLOR_BGR2GRAY);

        //应用高斯模糊，减少图像噪声
        Mat blurred = new Mat();
        GaussianBlur(gray, blurred, new Size(3, 3), 0);

        //边缘检测
        Mat edged = new Mat();
        Canny(blurred, edged, 75, 200);

        //这里可以根据需要添加其他图像处理步骤
        return edged;
    }
}
